import utils from '@/utils'
import { fetchList } from '@/api/article'
const article = {
  state: {
    articleList: []
  },
  getters: {
    articleList: state => state.articleList
  },
  mutations: {
    SET_ARTICLELIST: (state, articleList) => {
      state.articleList = articleList
    }
  },
  actions: {
    async getArticleList ({commit}) {
      let res = await fetchList({})
      let items = res.data.items
      console.log("items:",items)
      items.map(item => {
        item.article_labels = []
        item.time = new Date(item.created_at).getTime()
      })
      items = utils.bubbleSort(items, 'time', 'reverse')
      items.map((item, index) => {
        item.article_serial_number = index + 1
        delete item.time
      })
      commit('SET_ARTICLELIST', items)
      return items
    }
  }
}
export default article
